<template>
  <div>
    <!-- banner图 -->
    <div class="swipe-box">
      <van-swipe :autoplay="3000">
        <van-swipe-item v-for="(image, index) in images" :key="index" @click="linkUrl(image)">
          <div class="img-box">
            <img width="100%" :src="image.banner_path">
          </div>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<script>
import { getBanners } from "@/api/home";
import { get_logout } from "@/api/login";
import { removeToken } from "@/utils/auth";


export default {
  name: "BannerItem",
  data() {
    return {
      images: []
    };
  },
  methods: {
    async Banner() {
      try {
        let company_id = localStorage.getItem("companyId");
        let par = {
          company_id: company_id,
          model_id: 1
        };
        let query = Object.assign({}, par);
        let res = await getBanners(query);
        let result = res.data;
        if (result.status == 100) {
          this.images = result.data.rows;
        }
      } catch (error) {
        //   alert(JSON.stringify(error))
          if(error.status == 102){
            //   alert(11)
              this.get_out()
          }
      }

    },
    linkUrl(item){
      if (item.link_url) {
        window.location.href = item.link_url
      }
    },
      async get_out() {
      let query = Object.assign({});
      let { data } = await get_logout(query);
      if (data.status == 100) {
        this.$toast("请重新登录");
        //  window.localStorage.clear()
        window.localStorage.removeItem("companyId");
        window.localStorage.removeItem("person");
        window.localStorage.removeItem("user");
        window.localStorage.removeItem("Tokenkey");
        removeToken()
        this.$router.replace("/Login");
      }
    }
  },
  created() {
    setTimeout(() => {
      this.Banner(); 
    }, 1000);
  },
  mounted() {}
};
</script>

<style lang="scss" scoped>

</style>
